package com.fwtai.service.web;

import com.fwtai.bean.PageFormData;
import com.fwtai.config.LocalUserId;
import com.fwtai.tool.ToolClient;
import com.fwtai.web.ShareDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 欢迎页统计
 * @作者 田应平
 * @版本 v1.0
 * @QQ号码 444141300
 * @创建日期 2021-07-21 17:49:27
 * @官网 <url>http://www.fwtai.com</url>
*/
@Service
public class ShareService{

  @Resource
  private ShareDao shareDao;

  public String getMyShareListInfo(PageFormData formData){
    try {
      formData = ToolClient.dataTableMysql(formData);
      if(formData == null)return ToolClient.jsonValidateField();
      final Long userId = formData.getLong("userId");
      formData.put("loginId",userId == null ? Long.valueOf(LocalUserId.get()) : userId);
      final List<Map<String,Object>> list = shareDao.getMyShareListData(formData);
      /*list.forEach(item->{
        item.put("user_name",ToolString.replacePhone((String)item.get("user_name")));
      });*/
      return ToolClient.dataTableOK(list,shareDao.getMyShareListTotal(formData));
    } catch (final Exception e){
      return ToolClient.dataTableException();
    }
  }

  public String getMyTeamTotal(){
    final String loginId = LocalUserId.get();
    if(loginId == null){
      return ToolClient.accessLogin();
    }
    final Integer totalAll = shareDao.getShareTotalAll(loginId);//邀请总客户；
    final Integer currentDay = shareDao.getCurrentDay(loginId);//获取当天的邀请人
    final Integer last7Day = shareDao.getLast7Day(loginId);//获取最近7天的邀请人
    final Integer yesterday = shareDao.getYesterday(loginId);//获取昨天的邀请人
    final HashMap<String,Integer> result = new HashMap<>(4);
    result.put("totalAll",totalAll);
    result.put("currentDay",currentDay);
    result.put("last7Day",last7Day);
    result.put("yesterday",yesterday);
    return ToolClient.queryJson(result);
  }
}